home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / gdb-4.5 / dist / bfd / section.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-02  |  21.0 KB  |  794 lines

  1. /* Object file "section" support for the BFD library.
  2.    Copyright (C) 1990-1991 Free Software Foundation, Inc.
  3.    Written by Cygnus Support.
  4.  
  5. This file is part of BFD, the Binary File Descriptor library.
  6.  
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or
  10. (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21. /*
  22. SECTION
  23.     Sections
  24.  
  25.     Sections are supported in BFD in <<section.c>>.
  26.  
  27.     The raw data contained within a BFD is maintained through the
  28.     section abstraction.  A single BFD may have any number of
  29.     sections, and keeps hold of them by pointing to the first,
  30.     each one points to the next in the list.
  31.  
  32. @menu
  33. @* Section Input::
  34. @* Section Output::
  35. @* typedef asection::
  36. @* section prototypes::
  37. @end menu
  38.  
  39. INODE
  40. Section Input, Section Output, Sections, Sections
  41. SUBSECTION
  42.     Section Input
  43.  
  44.     When a BFD is opened for reading, the section structures are
  45.     created and attached to the BFD.
  46.  
  47.     Each section has a name which describes the section in the
  48.     outside world - for example, <<a.out>> would contain at least
  49.     three sections, called <<.text>>, <<.data>> and <<.bss>>. 
  50.  
  51.     Sometimes a BFD will contain more than the 'natural' number of
  52.     sections. A back end may attach other sections containing
  53.     constructor data, or an application may add a section (using
  54.     bfd_make_section) to the sections attached to an already open
  55.     BFD. For example, the linker creates a supernumary section
  56.     <<COMMON>> for each input file's BFD to hold information about
  57.     common storage.
  58.  
  59.     The raw data is not necessarily read in at the same time as
  60.     the section descriptor is created. Some targets may leave the
  61.     data in place until a <<bfd_get_section_contents>> call is
  62.     made. Other back ends may read in all the data at once - For
  63.     example; an S-record file has to be read once to determine the
  64.     size of the data. An IEEE-695 file doesn't contain raw data in
  65.     sections, but data and relocation expressions intermixed, so
  66.     the data area has to be parsed to get out the data and
  67.     relocations.
  68.  
  69. INODE
  70. Section Output, typedef asection, Section Input, Sections
  71.  
  72. SUBSECTION
  73.     Section Output
  74.  
  75.     To write a new object style BFD, the various sections to be
  76.     written have to be created. They are attached to the BFD in
  77.     the same way as input sections, data is written to the
  78.     sections using <<bfd_set_section_contents>>.  
  79.  
  80.     The linker uses the fields <<output_section>> and
  81.     <<output_offset>> to create an output file.
  82.  
  83.     The data to be written comes from input sections attached to
  84.     the output sections.  The output section structure can be
  85.     considered a filter for the input section, the output section
  86.     determines the vma of the output data and the name, but the
  87.     input section determines the offset into the output section of
  88.     the data to be written.
  89.  
  90.     Eg to create a section "O", starting at 0x100, 0x123 long,
  91.     containing two subsections, "A" at offset 0x0 (ie at vma
  92.     0x100) and "B" at offset 0x20 (ie at vma 0x120) the structures
  93.     would look like:
  94.  
  95. |   section name          "A"
  96. |     output_offset   0x00
  97. |     size            0x20
  98. |     output_section ----------->  section name    "O"
  99. |                             |    vma             0x100
  100. |   section name          "B" |    size            0x123
  101. |     output_offset   0x20    |
  102. |     size            0x103   |
  103. |     output_section  --------|
  104.  
  105.  
  106. SUBSECTION
  107.     Seglets
  108.  
  109.     The data within a section is stored in a <<seglet>>.  These
  110.     are much like the fixups in <<gas>>.  The seglet abstraction
  111.     allows the a section to grow and shrink within itself.
  112.  
  113.     A seglet knows how big it is, and which is the next seglet and
  114.     where the raw data for it is, and also points to a list of
  115.     relocations which apply to it.
  116.  
  117.     The seglet is used by the linker to perform relaxing on final
  118.     code.  The application creates code which is as big as
  119.     necessary to make it work without relaxing, and the user can
  120.     select whether to relax.  Sometimes relaxing takes a lot of
  121.     time.  The linker runs around the relocations to see if any
  122.     are attached to data which can be shrunk, if so it does it on
  123.     a seglet by seglet basis.
  124.  
  125. */
  126.  
  127.  
  128. #include "bfd.h"
  129. #include "sysdep.h"
  130. #include "libbfd.h"
  131.  
  132.  
  133. /*doc*
  134. INODE
  135. typedef asection, section prototypes, Section Output, Sections
  136. SUBSECTION
  137.     typedef asection
  138.  
  139.     The shape of a section struct:
  140.  
  141. CODE_FRAGMENT
  142. .
  143. .typedef struct sec 
  144. .{
  145. .        {* The name of the section, the name isn't a copy, the pointer is
  146. .        the same as that passed to bfd_make_section. *}
  147. .
  148. .    CONST char *name;
  149. .
  150. .
  151. .        {* Which section is it 0.nth      *}
  152. .
  153. .   int index;                      
  154. .
  155. .        {* The next section in the list belonging to the BFD, or NULL. *}
  156. .
  157. .    struct sec *next;
  158. .
  159. .        {* The field flags contains attributes of the section. Some of
  160. .           flags are read in from the object file, and some are
  161. .           synthesized from other information.  *}         
  162. .
  163. .    flagword flags;
  164. .
  165. .#define SEC_NO_FLAGS   0x000
  166. .
  167. .        {* Tells the OS to allocate space for this section when loaded.
  168. .           This would clear for a section containing debug information
  169. .           only. *}
  170. .          
  171. .
  172. .#define SEC_ALLOC      0x001
  173. .        {* Tells the OS to load the section from the file when loading.
  174. .           This would be clear for a .bss section *}
  175. .
  176. .#define SEC_LOAD       0x002
  177. .        {* The section contains data still to be relocated, so there will
  178. .           be some relocation information too. *}
  179. .
  180. .#define SEC_RELOC      0x004
  181. .
  182. .        {* Obsolete ? *}
  183. .
  184. .#define SEC_BALIGN     0x008
  185. .
  186. .        {* A signal to the OS that the section contains read only
  187. .          data. *}
  188. .#define SEC_READONLY   0x010
  189. .
  190. .        {* The section contains code only. *}
  191. .
  192. .#define SEC_CODE       0x020
  193. .
  194. .        {* The section contains data only. *}
  195. .
  196. .#define SEC_DATA        0x040
  197. .
  198. .        {* The section will reside in ROM. *}
  199. .
  200. .#define SEC_ROM        0x080
  201. .
  202. .        {* The section contains constructor information. This section
  203. .           type is used by the linker to create lists of constructors and
  204. .           destructors used by <<g++>>. When a back end sees a symbol
  205. .           which should be used in a constructor list, it creates a new
  206. .           section for the type of name (eg <<__CTOR_LIST__>>), attaches
  207. .           the symbol to it and builds a relocation. To build the lists
  208. .           of constructors, all the linker has to to is catenate all the
  209. .           sections called <<__CTOR_LIST__>> and relocte the data
  210. .           contained within - exactly the operations it would peform on
  211. .           standard data. *}
  212. .
  213. .#define SEC_CONSTRUCTOR 0x100
  214. .
  215. .        {* The section is a constuctor, and should be placed at the
  216. .          end of the . *}
  217. .
  218. .
  219. .#define SEC_CONSTRUCTOR_TEXT 0x1100
  220. .
  221. .#define SEC_CONSTRUCTOR_DATA 0x2100
  222. .
  223. .#define SEC_CONSTRUCTOR_BSS  0x3100
  224. .
  225. .
  226. .        {* The section has contents - a bss section could be
  227. .           <<SEC_ALLOC>> | <<SEC_HAS_CONTENTS>>, a debug section could be
  228. .           <<SEC_HAS_CONTENTS>> *}
  229. .
  230. .#define SEC_HAS_CONTENTS 0x200
  231. .
  232. .        {* An instruction to the linker not to output sections
  233. .          containing this flag even if they have information which
  234. .          would normally be written. *}
  235. .
  236. .#define SEC_NEVER_LOAD 0x400
  237. .
  238. .
  239. .       
  240. .   bfd_vma vma;
  241. .
  242. .        {* The size of the section in bytes, as it will be output.
  243. .           contains a value even if the section has no contents (eg, the
  244. .           size of <<.bss>>). This will be filled in after relocation *}
  245. .
  246. .   bfd_size_type _cooked_size;    
  247. .
  248. .        {* The size on disk of the section in bytes originally.  Normally this
  249. .        value is the same as the size, but if some relaxing has
  250. .        been done, then this value will be bigger.  *}
  251. .
  252. .   bfd_size_type _raw_size;    
  253. .
  254. .        {* If this section is going to be output, then this value is the
  255. .           offset into the output section of the first byte in the input
  256. .           section. Eg, if this was going to start at the 100th byte in
  257. .           the output section, this value would be 100. *}
  258. .
  259. .   bfd_vma output_offset;
  260. .
  261. .        {* The output section through which to map on output. *}
  262. .
  263. .   struct sec *output_section;
  264. .
  265. .        {* The alignment requirement of the section, as an exponent - eg
  266. .           3 aligns to 2^3 (or 8) *}
  267. .
  268. .   unsigned int alignment_power;
  269. .
  270. .        {* If an input section, a pointer to a vector of relocation
  271. .           records for the data in this section. *}
  272. .
  273. .   struct reloc_cache_entry *relocation;
  274. .
  275. .        {* If an output section, a pointer to a vector of pointers to
  276. .           relocation records for the data in this section. *}
  277. .
  278. .   struct reloc_cache_entry **orelocation;
  279. .
  280. .        {* The number of relocation records in one of the above  *}
  281. .
  282. .   unsigned reloc_count;
  283. .
  284. .        {* Information below is back end specific - and not always used
  285. .           or updated 
  286. .
  287. .           File position of section data    *}
  288. .
  289. .   file_ptr filepos;      
  290. .        
  291. .        {* File position of relocation info *}
  292. .
  293. .   file_ptr rel_filepos;
  294. .
  295. .        {* File position of line data       *}
  296. .
  297. .   file_ptr line_filepos;
  298. .
  299. .        {* Pointer to data for applications *}
  300. .
  301. .   PTR userdata;
  302. .
  303. .   struct lang_output_section *otheruserdata;
  304. .
  305. .        {* Attached line number information *}
  306. .
  307. .   alent *lineno;
  308. .        
  309. .        {* Number of line number records   *}
  310. .
  311. .   unsigned int lineno_count;
  312. .
  313. .        {* When a section is being output, this value changes as more
  314. .           linenumbers are written out *}
  315. .
  316. .   file_ptr moving_line_filepos;
  317. .
  318. .        {* what the section number is in the target world  *}
  319. .
  320. .   int target_index;
  321. .
  322. .   PTR used_by_bfd;
  323. .
  324. .        {* If this is a constructor section then here is a list of the
  325. .           relocations created to relocate items within it. *}
  326. .
  327. .   struct relent_chain *constructor_chain;
  328. .
  329. .        {* The BFD which owns the section. *}
  330. .
  331. .   bfd *owner;
  332. .
  333. .   boolean reloc_done;
  334. .     {* A symbol which points at this section only *}
  335. .   struct symbol_cache_entry *symbol;  
  336. .   struct symbol_cache_entry **symbol_ptr_ptr;
  337. .   struct bfd_seclet_struct *seclets_head;
  338. .   struct bfd_seclet_struct *seclets_tail;
  339. .} asection ;
  340. .
  341. .
  342. .#define BFD_ABS_SECTION_NAME "*ABS*"
  343. .#define BFD_UND_SECTION_NAME "*UND*"
  344. .#define BFD_COM_SECTION_NAME "*COM*"
  345. .
  346. .    {* the absolute section *}
  347. . extern   asection bfd_abs_section;
  348. .    {* Pointer to the undefined section *}
  349. . extern   asection bfd_und_section;
  350. .    {* Pointer to the common section *}
  351. . extern asection bfd_com_section;
  352. .
  353. . extern struct symbol_cache_entry *bfd_abs_symbol;
  354. . extern struct symbol_cache_entry *bfd_com_symbol;
  355. . extern struct symbol_cache_entry *bfd_und_symbol;
  356. .#define bfd_get_section_size_before_reloc(section) \
  357. .     (section->reloc_done ? (abort(),1): (section)->_raw_size)
  358. .#define bfd_get_section_size_after_reloc(section) \
  359. .     ((section->reloc_done) ? (section)->_cooked_size: (abort(),1))
  360. */
  361.  
  362.  
  363.  
  364. asection bfd_com_section = {  BFD_COM_SECTION_NAME ,0 };
  365. asection bfd_und_section = {  BFD_UND_SECTION_NAME ,0 };
  366. asection bfd_abs_section = {  BFD_ABS_SECTION_NAME ,0 };
  367.  
  368. struct symbol_cache_entry *bfd_abs_symbol;
  369. struct symbol_cache_entry *bfd_com_symbol;
  370. struct symbol_cache_entry *bfd_und_symbol;
  371.  
  372. /*
  373. INODE
  374. section prototypes,  , typedef asection, Sections
  375. SUBSECTION
  376.     section prototypes
  377.  
  378. These are the functions exported by the section handling part of
  379. <<libbfd>.
  380. */
  381.  
  382. /*
  383. FUNCTION 
  384.     bfd_get_section_by_name
  385.  
  386. SYNOPSIS
  387.     asection *bfd_get_section_by_name(bfd *abfd, CONST char *name);
  388.  
  389. DESCRIPTION
  390.     Runs through the provided @var{abfd} and returns the
  391.     <<asection>> who's name matches that provided, otherwise NULL.
  392.     @xref{Sections}, for more information.
  393.  
  394. */
  395.  
  396. asection *
  397. DEFUN(bfd_get_section_by_name,(abfd, name),
  398.       bfd *abfd AND
  399.       CONST char *name)
  400. {
  401.   asection *sect;
  402.  
  403.   for (sect = abfd->sections; sect != NULL; sect = sect->next)
  404.     if (!strcmp (sect->name, name)) return sect;
  405.   return NULL;
  406. }
  407.  
  408.  
  409. /*
  410. FUNCTION
  411.     bfd_make_section_old_way
  412.  
  413. SYNOPSIS
  414.     asection *bfd_make_section_old_way(bfd *, CONST char *name);
  415.  
  416. DESCRIPTION
  417.     This function creates a new empty section called @var{name}
  418.     and attaches it to the end of the chain of sections for the
  419.     BFD supplied. An attempt to create a section with a name which
  420.     is already in use, returns its pointer without changing the
  421.     section chain.
  422.  
  423.     It has the funny name since this is the way it used to be
  424.     before is was rewritten...
  425.  
  426.     Possible errors are:
  427.     o invalid_operation
  428.     If output has already started for this BFD.
  429.     o no_memory
  430.     If obstack alloc fails.
  431.  
  432. */
  433.  
  434.  
  435. asection *
  436. DEFUN(bfd_make_section_old_way,(abfd, name),
  437.       bfd *abfd AND
  438.       CONST char * name)
  439. {
  440.   asection *sec = bfd_get_section_by_name(abfd, name);
  441.   if (sec == (asection *)NULL) 
  442.     {
  443.       sec = bfd_make_section(abfd, name);
  444.     }
  445.   return sec;
  446. }
  447.  
  448.  
  449. /*
  450. FUNCTION
  451.     bfd_make_section
  452.  
  453. SYNOPSIS
  454.     asection * bfd_make_section(bfd *, CONST char *name);
  455.  
  456. DESCRIPTION
  457.     This function creates a new empty section called @var{name}
  458.     and attaches it to the end of the chain of sections for the
  459.     BFD supplied. An attempt to create a section with a name which
  460.     is already in use, returns NULL without changing the section
  461.     chain.
  462.  
  463.     Possible errors are:
  464.     o invalid_operation - If output has already started for this BFD.
  465.     o no_memory - If obstack alloc fails.
  466. */
  467.  
  468.  
  469.  
  470. sec_ptr
  471. DEFUN(bfd_make_section,(abfd, name),
  472.       bfd *abfd AND
  473.       CONST char * name)
  474. {
  475.   asection *newsect;  
  476.   asection **  prev = &abfd->sections;
  477.   asection * sect = abfd->sections;
  478.   
  479.   if (abfd->output_has_begun) {
  480.     bfd_error = invalid_operation;
  481.     return NULL;
  482.   }
  483.  
  484.   if (strcmp(name, BFD_ABS_SECTION_NAME) == 0) 
  485.   {
  486.     return &bfd_abs_section;
  487.   }
  488.   if (strcmp(name, BFD_COM_SECTION_NAME) == 0) 
  489.   {
  490.     return &bfd_com_section;
  491.   }
  492.   if (strcmp(name, BFD_UND_SECTION_NAME) == 0) 
  493.   {
  494.     return &bfd_und_section;
  495.   }
  496.   
  497.   while (sect) {
  498.     if (!strcmp(sect->name, name)) return NULL;
  499.     prev = §->next;
  500.     sect = sect->next;
  501.   }
  502.  
  503.   newsect = (asection *) bfd_zalloc(abfd, sizeof (asection));
  504.   if (newsect == NULL) {
  505.     bfd_error = no_memory;
  506.     return NULL;
  507.   }
  508.  
  509.   newsect->name = name;
  510.   newsect->index = abfd->section_count++;
  511.   newsect->flags = SEC_NO_FLAGS;
  512.  
  513.   newsect->userdata = 0;
  514.   newsect->next = (asection *)NULL;
  515.   newsect->relocation = (arelent *)NULL;
  516.   newsect->reloc_count = 0;
  517.   newsect->line_filepos =0;
  518.   newsect->owner = abfd;
  519.  
  520. /* Create a symbol whos only job is to point to this section. This is
  521.    usfull for things like relocs which are relative to the base of a
  522.    section
  523.  */
  524.   newsect->symbol = bfd_make_empty_symbol(abfd);
  525.   newsect->symbol->name = name;
  526.   newsect->symbol->value = 0;
  527.   newsect->symbol->section = newsect;
  528.   newsect->symbol->flags = BSF_SECTION_SYM;
  529.   
  530.  
  531.   newsect->symbol_ptr_ptr = &newsect->symbol;
  532.   
  533.   if (BFD_SEND (abfd, _new_section_hook, (abfd, newsect)) != true) {
  534.     free (newsect);
  535.     return NULL;
  536.   }
  537.  
  538.   *prev = newsect;
  539.   return newsect;
  540. }
  541.  
  542.  
  543. /*
  544. FUNCTION
  545.     bfd_set_section_flags
  546.  
  547. SYNOPSIS
  548.     boolean bfd_set_section_flags(bfd *, asection *, flagword);
  549.  
  550. DESCRIPTION
  551.     Attempts to set the attributes of the section named in the BFD
  552.     supplied to the value. Returns true on success, false on
  553.     error. Possible error returns are:
  554.  
  555.     o invalid operation
  556.     The section cannot have one or more of the attributes
  557.     requested. For example, a .bss section in <<a.out>> may not
  558.     have the <<SEC_HAS_CONTENTS>> field set.
  559.  
  560. */
  561.  
  562. boolean
  563. DEFUN(bfd_set_section_flags,(abfd, section, flags),
  564.      bfd *abfd AND
  565.      sec_ptr section AND
  566.      flagword flags)
  567. {
  568.   if ((flags & bfd_applicable_section_flags (abfd)) != flags) {
  569.     bfd_error = invalid_operation;
  570.     return false;
  571.   }
  572.  
  573.   section->flags = flags;
  574.   return true;
  575. }
  576.  
  577.  
  578. /*
  579. FUNCTION
  580.     bfd_map_over_sections
  581.  
  582. SYNOPSIS
  583.     void bfd_map_over_sections(bfd *abfd,
  584.                    void (*func)(bfd *abfd,
  585.                         asection *sect,
  586.                         PTR obj),
  587.                    PTR obj);
  588.  
  589. DESCRIPTION
  590.     Calls the provided function @var{func} for each section
  591.     attached to the BFD @var{abfd}, passing @var{obj} as an
  592.     argument. The function will be called as if by 
  593.  
  594. |    func(abfd, the_section, obj);
  595.  
  596.     This is the prefered method for iterating over sections, an
  597.     alternative would be to use a loop:
  598.  
  599. |       section *p;
  600. |       for (p = abfd->sections; p != NULL; p = p->next)
  601. |          func(abfd, p, ...)
  602.  
  603.  
  604. */
  605.  
  606. /*VARARGS2*/
  607. void
  608. DEFUN(bfd_map_over_sections,(abfd, operation, user_storage),
  609.       bfd *abfd AND
  610.       void EXFUN((*operation), (bfd *abfd,
  611.                 asection *sect,
  612.                 PTR obj)) AND
  613.       PTR user_storage)
  614. {
  615.   asection *sect;
  616.   int i = 0;
  617.   
  618.   for (sect = abfd->sections; sect != NULL; i++, sect = sect->next)
  619.     (*operation) (abfd, sect, user_storage);
  620.  
  621.   if (i != abfd->section_count)         /* Debugging */
  622.     abort();
  623. }
  624.  
  625.  
  626. /*
  627. FUNCTION
  628.     bfd_set_section_size
  629.  
  630. SYNOPSIS
  631.     boolean bfd_set_section_size(bfd *, asection *, bfd_size_type val);
  632.  
  633. DESCRIPTION
  634.     Sets @var{section} to the size @var{val}. If the operation is
  635.     ok, then <<true>> is returned, else <<false>>. 
  636.  
  637.     Possible error returns:
  638.     o invalid_operation
  639.     Writing has started to the BFD, so setting the size is invalid
  640.  
  641. */
  642.  
  643. boolean
  644. DEFUN(bfd_set_section_size,(abfd, ptr, val),
  645.       bfd *abfd AND
  646.       sec_ptr ptr AND
  647.       bfd_size_type val)
  648. {
  649.   /* Once you've started writing to any section you cannot create or change
  650.      the size of any others. */
  651.  
  652.   if (abfd->output_has_begun) {
  653.     bfd_error = invalid_operation;
  654.     return false;
  655.   }
  656.  
  657.   ptr->_cooked_size = val;
  658.   ptr->_raw_size = val;
  659.   
  660.   return true;
  661. }
  662.  
  663. /*
  664. FUNCTION
  665.     bfd_set_section_contents
  666.  
  667. SYNOPSIS
  668.     boolean bfd_set_section_contents
  669.          (bfd *abfd,        
  670.          asection *section,
  671.          PTR data,
  672.          file_ptr offset,
  673.          bfd_size_type count);
  674.  
  675.  
  676. DESCRIPTION
  677.     Sets the contents of the section @var{section} in BFD
  678.     @var{abfd} to the data starting in memory at @var{data}. The
  679.     data is written to the output section starting at offset
  680.     @var{offset} for @var{count} bytes. 
  681.  
  682.  
  683.  
  684.     Normally <<true>> is returned, else <<false>>. Possible error
  685.     returns are:
  686.     o no_contents
  687.     The output section does not have the <<SEC_HAS_CONTENTS>>
  688.     attribute, so nothing can be written to it.
  689.     o and some more too
  690.  
  691.     This routine is front end to the back end function
  692.     <<_bfd_set_section_contents>>.
  693.  
  694.  
  695. */
  696.  
  697. boolean
  698. DEFUN(bfd_set_section_contents,(abfd, section, location, offset, count),
  699.       bfd *abfd AND
  700.       sec_ptr section AND
  701.       PTR location AND
  702.       file_ptr offset AND
  703.       bfd_size_type count)
  704. {
  705.   if (!(bfd_get_section_flags(abfd, section) & SEC_HAS_CONTENTS)) 
  706.       {
  707.         bfd_error = no_contents;
  708.         return(false);
  709.       } 
  710.  
  711.   if (BFD_SEND (abfd, _bfd_set_section_contents,
  712.                 (abfd, section, location, offset, count))) 
  713.       {
  714.         abfd->output_has_begun = true;
  715.         return true;
  716.       }
  717.  
  718.   return false;
  719. }
  720.  
  721. /*
  722. FUNCTION
  723.     bfd_get_section_contents
  724.  
  725. SYNOPSIS
  726.     boolean bfd_get_section_contents 
  727.         (bfd *abfd, asection *section, PTR location,
  728.          file_ptr offset, bfd_size_type count);
  729.  
  730. DESCRIPTION
  731.     This function reads data from @var{section} in BFD @var{abfd}
  732.     into memory starting at @var{location}. The data is read at an
  733.     offset of @var{offset} from the start of the input section,
  734.     and is read for @var{count} bytes.
  735.  
  736.     If the contents of a constuctor with the <<SEC_CONSTUCTOR>>
  737.     flag set are requested, then the @var{location} is filled with
  738.     zeroes. If no errors occur, <<true>> is returned, else
  739.     <<false>>.
  740.  
  741.  
  742.  
  743. */
  744. boolean
  745. DEFUN(bfd_get_section_contents,(abfd, section, location, offset, count),
  746.       bfd *abfd AND
  747.       sec_ptr section AND
  748.       PTR location AND
  749.       file_ptr offset AND
  750.       bfd_size_type count)
  751. {
  752.   if (section->flags & SEC_CONSTRUCTOR) 
  753.       {
  754.         memset(location, 0, (unsigned)count);
  755.         return true;
  756.       }
  757.   else 
  758.       {
  759.         return  (BFD_SEND (abfd, _bfd_get_section_contents,
  760.                            (abfd, section, location, offset, count)));
  761.       }
  762. }
  763.  
  764.  
  765. /* Initialize the internal data structures */
  766. void
  767. DEFUN_VOID(bfd_section_init)
  768. {
  769.  
  770.   bfd_com_symbol = (asymbol *)zalloc(sizeof(asymbol));
  771.   bfd_com_symbol->name = BFD_COM_SECTION_NAME;
  772.   bfd_com_symbol->flags = BSF_SECTION_SYM;
  773.   bfd_com_symbol->section = &bfd_com_section;
  774.   bfd_com_section.symbol = bfd_com_symbol;
  775.   bfd_com_section.symbol_ptr_ptr = &bfd_com_symbol;
  776.   bfd_com_section.output_section = &bfd_com_section;
  777.  
  778.   bfd_und_symbol = (asymbol *)zalloc(sizeof(asymbol));
  779.   bfd_und_symbol->name = BFD_UND_SECTION_NAME;
  780.   bfd_und_symbol->flags = BSF_SECTION_SYM;
  781.   bfd_und_symbol->section = &bfd_und_section;
  782.   bfd_und_section.symbol = bfd_und_symbol;
  783.   bfd_und_section.symbol_ptr_ptr = &bfd_und_symbol;
  784.   bfd_und_section.output_section = &bfd_und_section;  
  785.  
  786.   bfd_abs_symbol = (asymbol *)zalloc(sizeof(asymbol));
  787.   bfd_abs_symbol->name = BFD_ABS_SECTION_NAME;
  788.   bfd_abs_symbol->flags = BSF_SECTION_SYM;
  789.   bfd_abs_symbol->section = &bfd_abs_section;
  790.   bfd_abs_section.symbol = bfd_abs_symbol;
  791.   bfd_abs_section.symbol_ptr_ptr = &bfd_abs_symbol;
  792.   bfd_abs_section.output_section = &bfd_abs_section;  
  793. }
  794.